import Moya

enum NetworkService {
    case getUsers
    case test
}

extension NetworkService: TargetType {

    var baseURL: URL {
        return URL(string: "http://localhost:8080")!
    }

    var path: String {
        switch self {
        case .getUsers:
            return "/users"
        case .test:
            return "/hello"
        }
    }

    var method: Method {
        switch self {
        case .getUsers:
            return .get
        case .test:
            return .get
        }
    }

    var sampleData: Data {
        return Data()
    }

    var task: Task {
        switch self {
        case .getUsers:
            return .requestPlain
        case .test:
            return .requestPlain
        }
        //表示没有参数的网络请求
//        case .getUsers(let userId):
//        return .requestParameters(parameters: ["userId": userId], encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return ["Content-type": "application/json"]
    }
}

let provider = MoyaProvider<NetworkService>()
